import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.util.Arrays;


public class UDPFileClient {

	public static void main1(String[] args) throws IOException {
		DatagramSocket client = new DatagramSocket();
		byte[] buffer = "ivo.txt".getBytes();
		DatagramPacket out = new DatagramPacket(buffer, buffer.length,new InetSocketAddress("localhost",1234));
		client.send(out);
		buffer = new byte[255];
		DatagramPacket in = new DatagramPacket(buffer, buffer.length);
		client.receive(in);
		System.out.println(Arrays.toString(buffer));
		client.close();
	}
	
	public static void main(String[] args) throws IOException {
		
		DatagramSocket receiver = new DatagramSocket(4444);
		while (true) {
			byte[] buffer = new byte[256];
			DatagramPacket in = new DatagramPacket(buffer, buffer.length);
			receiver.receive(in);
			String received = new String(buffer,0,in.getLength());
			System.out.println(received);
		}
	}

}
